package web1.bean;

public class CaluculatorBean {
	private double firstNum=0;
	private double secondNum=0;
	private char operator='+';
	private double result=0;
	
	public double getFirstNum() {
		return firstNum;
	}
	public void setFirstNum(double firstNum) {
		this.firstNum = firstNum;
	}
	public double getSecondNum() {
		return secondNum;
	}
	public void setSecondNum(double secondNum) {
		this.secondNum = secondNum;
	}
	public char getOperator() {
		return operator;
	}
	public void setOperator(char operator) {
		this.operator = operator;
	}
	public double getResult() {
		return result;
	}
	public void setResult(double result) {
		this.result = result;
	}
	
	//计算
	public void calculate() {
		switch(this.operator) {
		case '+':{
			this.result=this.firstNum+this.secondNum;
			break;
		}
		case '-':{
			this.result=this.firstNum-this.secondNum;
			break;
		}
		case '*':{
			this.result=this.firstNum*this.secondNum;
			break;
		}
		case '/':{
			if(this.secondNum==0)
				throw new RuntimeException("被除数不能为0！！！");
			this.result=this.firstNum/this.secondNum;
			this.result=new java.math.BigDecimal(this.result).setScale(2,java.math.BigDecimal.ROUND_HALF_UP).doubleValue();
			break;
		}
		default:
			throw new RuntimeException("对不起，你输入的运算符非法！");
			
		
		}
	}
}
